package messageLogger.helper;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;

public class ClipboardHelper {

	private DataFlavor stringDataFlavor;
	private Clipboard clipboard;

	public ClipboardHelper() throws Exception {
		stringDataFlavor = new DataFlavor(
				"application/x-java-serialized-object; class=java.lang.String");
		clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	}

	public String getStringFromClipboard() {
		Transferable transferable = clipboard.getContents(this);
		if (transferable.isDataFlavorSupported(stringDataFlavor)) {
			try {
				return (String) transferable.getTransferData(stringDataFlavor);
			} catch (Exception e) {
				e.printStackTrace();
				return null;
			}
		} else {
			return null;
		}

	}
	

	public static void main(String[] args) throws Exception {
		ClipboardHelper clipboardHelper = new ClipboardHelper();
		System.out.println(clipboardHelper.getStringFromClipboard());
	}
}
